from starlette.authentication import requires
from fastapi import APIRouter, Request, Depends

from myDSM.db_config.odmantic_config import create_db_engine
from myDSM.repository.disorders_repo import (
    DisorderKindRepository,
    MentalDisorderRepository)

router = APIRouter()


@router.get("/disorders/name")
@requires("authenticated")
async def get_disorder_by_name(request: Request, name: str,
                               engine=Depends(create_db_engine)):
    repo: MentalDisorderRepository = MentalDisorderRepository(engine)
    return await repo.get_disorder_by_name(name)


@router.get("/disorders/all")
@requires("authenticated")
async def get_all_disorders(request: Request,
                            engine=Depends(create_db_engine)):
    repo: MentalDisorderRepository = MentalDisorderRepository(engine)
    return await repo.get_all_disorders()


@router.get("/disorders/kind/name")
@requires("authenticated")
async def get_disorder_kind_by_name(request: Request, name: str,
                                    engine=Depends(create_db_engine)):
    repo: DisorderKindRepository = DisorderKindRepository(engine)
    return await repo.get_disorder_kind_by_name(name)


@router.get("/disorders/kind/all")
@requires("authenticated")
async def get_all_disorder_kinds(request: Request,
                                 engine=Depends(create_db_engine)):
    repo: DisorderKindRepository = DisorderKindRepository(engine)
    return await repo.get_all_disorder_kinds()
